package com.zdgk.core.web.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zdgk.core.web.entity.RuleInfo;
import com.zdgk.core.web.mapper.RuleInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RuleService {
    @Autowired
    private RuleInfoMapper ruleInfoMapper;

    public List<RuleInfo> getAllRules() {
        return ruleInfoMapper.selectList(new QueryWrapper<RuleInfo>().lambda().orderByAsc(RuleInfo::getAddress104));
    }

    public void saveAll(List<RuleInfo> ruleInfos) {
        ruleInfoMapper.delete(null);
        for (RuleInfo ruleInfo : ruleInfos) {
            if(ruleInfo.getId().contains("new")){
                ruleInfo.setId(null);
            }
            ruleInfoMapper.insert(ruleInfo);
        }
    }
}
